package com.zdy.im.user.controller;



import java.util.ArrayList;
import java.util.List;

import com.sixeco.framework.common.api.ApiDoc;
import com.sixeco.framework.common.data.BasePage;
import com.sixeco.framework.common.enums.SysResultCodeEnum;
import com.sixeco.framework.http.data.vo.HttpRequestByIdVo;
import com.sixeco.framework.http.data.vo.ResponseResultList;
import com.sixeco.framework.http.handler.OutputResponse;
import com.zdy.im.user.UrlCommand;
import com.zdy.im.user.dto.request.ImUserFriendShipRequestDto;
import com.zdy.im.user.dto.response.ImUserFriendShipResponseDto;
import com.zdy.im.user.facade.ImUserFriendShipFacade;
import com.zdy.im.user.service.ImUserFriendShipService;
import com.zdy.im.user.vo.request.ImUserFriendQueryRequestVo;
import com.zdy.im.user.vo.request.ImUserFriendShipQueryRequestVo;
import com.zdy.im.user.vo.request.UserRoomFriendQueryRequestVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;

import com.zdy.im.user.vo.response.ImUserFriendShipShowResponseVo;

/**
 * @Title: ImUserFriendShipController.java
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 * @version V1.0
 *  <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 * @Description: TODO(说明) 对象缓存统一模板实现类;
 */
@ApiDoc(
        module = "用户好友列关系表模块", isApp = true
)
@Controller
public class ImUserFriendShipController {

    @Autowired
    private ImUserFriendShipFacade imUserFriendShipFacade;

    @Autowired
    private ImUserFriendShipService imUserFriendShipService;



    /**
    * @Title: test测试生成类分页信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "分页获取用户好友列关系表信息",
            request = ImUserFriendShipQueryRequestVo.class,
            response = ImUserFriendShipShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserFriendShip_pageList, method = RequestMethod.GET)
    public void list(OutputResponse out, ImUserFriendShipQueryRequestVo imUserFriendShipQueryRequestVo){
            ImUserFriendShipRequestDto imUserFriendShipRequestDto = ImUserFriendShipRequestDto.build( ).clone(imUserFriendShipQueryRequestVo);

        BasePage page =  BasePage.build().toPageSize(imUserFriendShipQueryRequestVo.getPageSize()).toPageNo(imUserFriendShipQueryRequestVo.getPageNo());
        page.toParamObject(imUserFriendShipRequestDto );
        ResponseResultList<ImUserFriendShipResponseDto> resultList = imUserFriendShipService.getImUserFriendShipByNextPage(page);

        if(null == resultList || resultList.getList().isEmpty() ){
            out.writeSuccess();
            return;
        }
        List<ImUserFriendShipShowResponseVo> listVo = new ArrayList<>();
        resultList.getList().forEach(e -> listVo.add(ImUserFriendShipShowResponseVo.build().clone(e)));

        ResponseResultList list =  ResponseResultList.build().toList(listVo)
                .toIsNextPage(resultList.getIsNextPage())
                .toPageIndex(resultList.getPageIndex())
                .toTotal(resultList.getTotal());
        out.write(list);
    }





    /**
    * @Title: 查看test测试生成类信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "查看用户好友列关系表信息",
            request = HttpRequestByIdVo.class,
            response = ImUserFriendShipShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserFriendShip_info ,method = RequestMethod.GET)
    public void detail(OutputResponse out, HttpRequestByIdVo idRequestVo){
        if (idRequestVo.getId() == 0) {
            out.write(SysResultCodeEnum.SYS_WEB_ID_INFO_NO_EXIST);
            return ;
        }
        ImUserFriendShipResponseDto imUserFriendShipResponseDto = imUserFriendShipService.getImUserFriendShipById(idRequestVo.getId());
        ImUserFriendShipShowResponseVo vo =  ImUserFriendShipShowResponseVo.build().clone(imUserFriendShipResponseDto);
        out.write(vo);
    }

    @ApiDoc(
            value = "获取用户好友列表信息",
            request = ImUserFriendQueryRequestVo.class,
            response = ImUserFriendShipShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserFriendShip_list, method = RequestMethod.GET)
    public void getlist(OutputResponse out, ImUserFriendQueryRequestVo imUserFriendQueryRequestVo){
        if (imUserFriendQueryRequestVo.getUserId() == 0) {
            out.write(SysResultCodeEnum.SYS_WEB_ID_INFO_NO_EXIST);
            return ;
        }
        ResponseResultList<ImUserFriendShipShowResponseVo> resultList = imUserFriendShipFacade.selectListByUserId(imUserFriendQueryRequestVo);
        out.write(resultList);
    }

    @ApiDoc(
            value = "群加好友--可添加好友列表信息",
            request = UserRoomFriendQueryRequestVo.class,
            response = ImUserFriendShipShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserFriendShip_roomFridenList, method = RequestMethod.GET)
    public void roomFriendList(OutputResponse out, UserRoomFriendQueryRequestVo imUserFriendQueryRequestVo){
        if (imUserFriendQueryRequestVo.getRoomId() == 0 || imUserFriendQueryRequestVo.getUserId() == 0) {
            out.write(SysResultCodeEnum.SYS_WEB_ID_INFO_NO_EXIST);
            return ;
        }
        ResponseResultList<ImUserFriendShipShowResponseVo> resultList = imUserFriendShipFacade.selectRoomFridenList(imUserFriendQueryRequestVo);
        out.write(resultList);
    }

//    @ApiDoc(
//            value = "群加好友--可添加好友列表信息",
//            request = UserRoomFriendQueryRequestVo.class,
//            response = ImUserFriendShipShowResponseVo.class
//    )
//    @RequestMapping(value = UrlCommand.user_imUserFriendShip_roomFridenList, method = RequestMethod.GET)
//    public void roomFriendList(OutputResponse out, UserRoomFriendQueryRequestVo imUserFriendQueryRequestVo){
//        if (imUserFriendQueryRequestVo.getRoomId() == 0 || imUserFriendQueryRequestVo.getUserId() == 0) {
//            out.write(SysResultCodeEnum.SYS_WEB_ID_INFO_NO_EXIST);
//            return ;
//        }
//        ResponseResultList<ImUserFriendShipShowResponseVo> resultList = imUserFriendShipFacade.selectRoomFridenList(imUserFriendQueryRequestVo);
//        out.write(resultList);
//    }
}
